home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 001-025 / disk_008 / src / save1.window.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  8KB  |  336 lines

  1. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1984. */
  2.  
  3. #include <exec/types.h>
  4. #include <exec/io.h>
  5. #include <intuition/intuition.h>
  6. #include <stdio.h>
  7. #include "config.h"   /* for ROWNO and COLNO */
  8. #include "def.arrows.h"
  9.  
  10. #define ICON_REV       0
  11. #define GRAPHICS_REV   29
  12. #define INTUITION_REV  29
  13.  
  14. struct IntuitionBase *IntuitionBase;
  15. struct GfxBase *GfxBase;
  16. char *IconBase;
  17.  
  18. struct Image URImage = { 0,0,22,10,2,(short *)&UPRIGHTdata,   0x3, 0, NULL };
  19. struct Image DRImage = { 0,0,22,10,2,(short *)&DOWNRIGHTdata, 0x3, 0, NULL };
  20. struct Image RImage  = { 0,0,22,10,2,(short *)&RIGHTdata,     0x3, 0, NULL };
  21. struct Image DImage  = { 0,0,22,10,2,(short *)&DOWNdata,      0x3, 0, NULL };
  22. struct Image UImage  = { 0,0,22,10,2,(short *)&UPdata,        0x3, 0, NULL };
  23. struct Image LImage  = { 0,0,22,10,2,(short *)&LEFTdata,      0x3, 0, NULL };
  24. struct Image DLImage = { 0,0,22,10,2,(short *)&DOWNLEFTdata,  0x3, 0, NULL };
  25. struct Image ULImage = { 0,0,22,10,2,(short *)&UPLEFTdata,    0x3, 0, NULL };
  26.  
  27. struct Gadget URGadget = { NULL,      436, 0, 22,10,
  28.             GADGHCOMP | GADGIMAGE, GADGIMMEDIATE, BOOLGADGET,
  29.             (APTR)&URImage, NULL, NULL, 0, NULL, 'u', NULL };
  30. struct Gadget DRGadget = { &URGadget, 568, 0, 22,10,
  31.             GADGHCOMP | GADGIMAGE, GADGIMMEDIATE, BOOLGADGET,
  32.             (APTR)&DRImage, NULL, NULL, 0, NULL, 'n', NULL };
  33. struct Gadget RGadget  = { &DRGadget, 490, 0, 22,10,
  34.             GADGHCOMP | GADGIMAGE, GADGIMMEDIATE, BOOLGADGET,
  35.             (APTR)&RImage, NULL, NULL, 0, NULL, 'l', NULL };
  36. struct Gadget DGadget  = { &RGadget,  544, 0, 22,10,
  37.             GADGHCOMP | GADGIMAGE, GADGIMMEDIATE, BOOLGADGET,
  38.             (APTR)&DImage, NULL, NULL, 0, NULL, 'j', NULL };
  39. struct Gadget UGadget  = { &DGadget,  412, 0, 22,10,
  40.             GADGHCOMP | GADGIMAGE, GADGIMMEDIATE, BOOLGADGET,
  41.             (APTR)&UImage, NULL, NULL, 0, NULL, 'k', NULL };
  42. struct Gadget LGadget  = { &UGadget,  466, 0, 22,10,
  43.             GADGHCOMP | GADGIMAGE, GADGIMMEDIATE, BOOLGADGET,
  44.             (APTR)&LImage, NULL, NULL, 0, NULL, 'h', NULL };
  45. struct Gadget DLGadget = { &LGadget,  520, 0, 22,10,
  46.             GADGHCOMP | GADGIMAGE, GADGIMMEDIATE, BOOLGADGET,
  47.             (APTR)&DLImage, NULL, NULL, 0, NULL, 'b', NULL };
  48. struct Gadget ULGadget = { &DLGadget, 388, 0, 22,10,
  49.             GADGHCOMP | GADGIMAGE, GADGIMMEDIATE, BOOLGADGET,
  50.             (APTR)&ULImage, NULL, NULL, 0, NULL, 'y', NULL };
  51.  
  52. struct Window *HackWindow;
  53. struct NewWindow NewHackWindow = {
  54.   0,0,640,200, -1,-1,   /* left, top, width, height, detailpen, blockpen */
  55.   CLOSEWINDOW | RAWKEY | MENUPICK | GADGETDOWN,  /* idcmpf flags */
  56.   WINDOWDEPTH | WINDOWCLOSE | ACTIVATE,
  57.   &ULGadget, NULL, "HACK V1.0 - Ported by John A. Toebes, VIII",
  58.   NULL, NULL, 640,200,640,200, WBENCHSCREEN };
  59.  
  60. struct IOStdReq consoleIO;
  61.  
  62. #define HO "\x9BH"
  63. #define CL "\x0C"
  64. #define CE "\x9BK"
  65. #define UP "\x0B"
  66. #define CM "\x9B%d;%dH"
  67. #define ND "\x09"
  68. #define XD "\x9BB"
  69. #define BC "\x08"
  70. #define SO "\x9B4m"
  71. #define SE "\x9B0m"
  72. #define BELL 7
  73. int myx, myy;
  74.  
  75. startup()
  76. {
  77. }
  78.  
  79. /* Cursor movements */
  80. extern xchar curx, cury;
  81.  
  82. curs(x,y)
  83. register int x,y;   /* not xchar: perhaps xchar is unsigned and
  84.             curx-x would be unsigned as well */
  85. {
  86.    if (y != cury || x != curx)
  87.     myprintf(CM, y, x);
  88.    curx = x;
  89.    cury = y;
  90. }
  91.  
  92. cl_end() {
  93.     myprintf(CE);
  94. }
  95.  
  96. clear_screen() {
  97.     myprintf(CL);
  98.     curx = cury = 1;
  99. }
  100.  
  101. home()
  102. {
  103.     myprintf(HO);
  104.     curx = cury = 1;
  105. }
  106.  
  107. standoutbeg()
  108. {
  109.     myprintf(SO);
  110. }
  111.  
  112. standoutend()
  113. {
  114.     myprintf(SE);
  115. }
  116.  
  117. backsp()
  118. {
  119.     myprintf(BC);
  120.     curx--;
  121. }
  122.  
  123. bell()
  124. {
  125.     myputchar(BELL);
  126. }
  127.  
  128. delay_output()
  129. {
  130.    /* delay 40 ms, 50 ticks/sec    */
  131.    Delay (2);
  132. }
  133.  
  134. initterm()
  135.    {
  136.    if ( (IntuitionBase = (struct IntuitionBase *)
  137.     OpenLibrary("intuition.library", INTUITION_REV)) == NULL)
  138.     exit(2);
  139.  
  140.    if ( (GfxBase = (struct GfxBase *)
  141.     OpenLibrary("graphics.library",GRAPHICS_REV)) == NULL)
  142.     exit(3);
  143.  
  144.    if ( (IconBase = (char *)
  145.     OpenLibrary("icon.library",ICON_REV)) == NULL)
  146.     exit(3);
  147.  
  148.    if ( (HackWindow = (struct Window *)
  149.     OpenWindow(&NewHackWindow)) == NULL)
  150.     exit(5);
  151.  
  152.    consoleIO.io_Data = (char *) HackWindow;
  153.    consoleIO.io_Length = sizeof(*HackWindow);
  154.    if (OpenDevice("console.device",0, &consoleIO, 0) != 0)
  155.     exit(6);
  156.    }
  157.  
  158. hackexit(code)
  159. int code;
  160.    {
  161.    CloseWindow(HackWindow);
  162.    exit(code);
  163.    }
  164.  
  165. myputchar(c)
  166. char c;
  167.    {
  168.     consoleIO.io_Command = CMD_WRITE;
  169.     consoleIO.io_Data = &c;
  170.     consoleIO.io_Length = 1;
  171.     DoIO(&consoleIO);
  172.    }
  173.  
  174. inchar()
  175.    {
  176.    struct IntuiMessage *Message, *GetMsg();
  177.    int c;
  178.    ULONG class;
  179.    USHORT code, qual;
  180.  
  181.    c = 0;
  182.    while(!c)
  183.       {
  184.       while( (Message = GetMsg(HackWindow->UserPort)) == NULL)
  185.          Wait( 1 << HackWindow->UserPort->mp_SigBit );
  186.  
  187.       class = Message->Class;
  188.       qual = Message->Qualifier;
  189.       code = Message->Code;
  190.       if (class == GADGETDOWN)
  191.     {
  192.     struct Gadget *gadget;
  193.     gadget = (struct Gadget *)Message->IAddress;
  194.     code = gadget->GadgetID;
  195.     }
  196.       ReplyMsg(Message);
  197.  
  198.       switch(class)
  199.          {
  200.          case CLOSEWINDOW:
  201. #ifdef DEBUG
  202.         printf("got an eof message\n");
  203. #endif
  204.             c = EOF;
  205.             break;
  206.     case GADGETDOWN:
  207. #ifdef DEBUG
  208.         printf("Got a gedget selection on %d\n", code);
  209. #endif
  210.         c = code;
  211.         break;
  212.          case RAWKEY:
  213. #ifdef DEBUG
  214.         printf("Got a key code=%d qual=%08x\n", code, qual);
  215. #endif
  216.             c = cnvrtkey(code,qual);
  217. #ifdef DEBUG
  218.         printf("  it converts to %d\n", c);
  219. #endif
  220.             break;
  221.          default:
  222. #ifdef DEBUG
  223.         printf("got unknown code %08x\n", class);
  224. #endif
  225.             c = EOF;
  226.             break;
  227.          }
  228.       }
  229.    return(c);
  230.    }
  231.  
  232. #define NORMAL 0
  233. #define SHIFTED 1
  234. #define CONTROL 2
  235. #define ALTED 3
  236. short lookup[4][96] =
  237. {
  238. /* unshifted table */
  239.     '`',    '1',    '2',    '3',    '4',    '5',    '6',    '7',
  240.     '8',    '9',    '0',    '-',    '=',    '\\',    0,    '0',
  241.     'q',    'w',    'e',    'r',    't',    'y',    'u',    'i',
  242.     'o',    'p',    '[',    ']',    0,    'b',    'j',    'n',
  243.     'a',    's',    'd',    'f',    'g',    'h',    'j',    'k',
  244.     'l',    ';',    '\'',    0,    0,    'h',    '.',    'l',
  245.     0,    'z',    'x',    'c',    'v',    'b',    'n',    'm',
  246.     ',',    '.',    '/',    0,    '.',    'y',    'k',    'u',
  247.     ' ',    8,    'i',    '\n',    '\n',    022,    8,    0,
  248.     0,    0,    '-',    0,    'k',    'j',    'l',    'h',
  249.     0,    0,    0,    0,    0,    0,    0,    0,
  250.     0,    0,    0,    0,    0,    0,    0,    '?',
  251.  
  252. /* shifted table */
  253.     '~',    '!',    '@',    '#',    '$',    '%',    '^',    '&',
  254.     '*',    '(',    ')',    '_',    '+',    '|',    0,    '0',
  255.     'Q',    'W',    'E',    'R',    'T',    'Y',    'U',    'I',
  256.     'O',    'P',    '{',    '}',    0,    'B',    'J',    'N',
  257.     'A',    'S',    'D',    'F',    'G',    'H',    'J',    'K',
  258.     'L',    ':',    '"',    0,    0,    'H',    '.',    'L',
  259.     0,    'Z',    'X',    'C',    'V',    'B',    'N',    'M',
  260.     '<',    '>',    '?',    0,    '.',    'Y',    'K',    'U',
  261.     ' ',    'H',    'I',    '\N',    '\N',    022,    'H',    0,
  262.     0,    0,    '-',    0,    'K',    'J',    'L',    'H',
  263.     0,    0,    0,    0,    0,    0,    0,    0,
  264.     0,    0,    0,    0,    0,    0,    0,    '?',
  265.  
  266. /* controlled table */
  267.     0,    0,    0,    0,    0,    0,    0,    0,
  268.     0,    0,    0,    0,    0,    EOF,    0,    0,
  269.     0,    0,    EOF,    022,    0,    0,    0,    0,
  270.     0,    020,    0,    0,    0,    0,    0,    0,
  271.     0,    0,    EOF,    EOF,    0,    0,    0,    0,
  272.     0,    0,    0,    0,    0,    0,    0,    0,
  273.     0,    0,    0,    EOF,    0,    0,    0,    0,
  274.     0,    0,    0,    0,    0,    0,    0,    0,
  275.     0,    0,    0,    0,    0,    0,    0,    0,
  276.     0,    0,    0,    0,    0,    0,    0,    0,
  277.     0,    0,    0,    0,    0,    0,    0,    0,
  278.     0,    0,    0,    0,    0,    0,    0,    '?',
  279.  
  280. /* alted table */
  281.     '`',    '1',    '2',    '3',    '4',    '5',    '6',    '7',
  282.     '8',    '9',    '0',    '-',    '=',    '\\',    0,    '0',
  283.     'q',    'w',    'e',    'r',    't',    'y',    'u',    'i',
  284.     'o',    'p',    '[',    ']',    0,    'b',    'j',    'n',
  285.     'a',    's',    'd',    'f',    'g',    'h',    'j',    'k',
  286.     'l',    ';',    '\'',    0,    0,    'h',    '.',    'l',
  287.     0,    'z',    'x',    'c',    'v',    'b',    'n',    'm',
  288.     ',',    '.',    '?',    0,    '.',    'y',    'k',    'u',
  289.     ' ',    'h',    'i',    '\n',    '\n',    022,    'h',    0,
  290.     0,    0,    '-',    0,    'k',    'j',    'l',    'h',
  291.     0,    0,    0,    0,    0,    0,    0,    0,
  292.     0,    0,    0,    0,    0,    0,    0,    '?'
  293. };
  294.  
  295. int cnvrtkey(code, qual )
  296. USHORT code, qual;
  297.    {
  298.    int table;
  299.  
  300.    if (code > 0x5f)
  301.       return(0);
  302.  
  303.    if (qual & (IEQUALIFIER_LSHIFT | IEQUALIFIER_RSHIFT))
  304.       table = SHIFTED;
  305.    else if (qual & (IEQUALIFIER_LALT | IEQUALIFIER_RALT))
  306.        table = ALTED;
  307.    else if (qual & (IEQUALIFIER_CONTROL))
  308.       table = CONTROL;
  309.    else
  310.       table = NORMAL;
  311.    return((int)lookup[table][code]);
  312.    }
  313.  
  314. myputs(str)
  315. char *str;
  316.    {
  317.     consoleIO.io_Command = CMD_WRITE;
  318.     consoleIO.io_Data = str;
  319.     consoleIO.io_Length = -1;
  320.     DoIO(&consoleIO);
  321.     myputchar("\n");
  322.    }
  323.  
  324. /*VARARGS1*/
  325. myprintf(str,a1,a2,a3,a4,a5,a6,a7,a8,a9)
  326. char *str,*a1,*a2,*a3,*a4,*a5,*a6,*a7,*a8,*a9;
  327.    {
  328.     char buf[128];
  329.  
  330.     sprintf(&buf,str,a1,a2,a3,a4,a5,a6,a7,a8,a9);
  331.     consoleIO.io_Command = CMD_WRITE;
  332.     consoleIO.io_Data = &buf;
  333.     consoleIO.io_Length = -1;
  334.     DoIO(&consoleIO);
  335.    }
  336.